//
//  K_RankingVC.m
//  K-Music
//
//  Created by CHUN on 16/1/25.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "K_RankingVC.h"
#import "K_ROOMCell.h"
#import "K_Mode.h"

@interface K_RankingVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
{
    
}
@property(nonatomic,strong)UICollectionView * collectionView;

@end

@implementation K_RankingVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.navigationItem.title = @"人气榜";
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"back" highIcon:@"back" target:self action:@selector(back_back)];

    
    [self creatUI];
    
    
}

- (void)back_back
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)creatUI
{
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc]init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    _collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WIDTH  , HEIGHT-114+49)collectionViewLayout:flowLayout];
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
    _collectionView.backgroundColor=[UIColor whiteColor];
    
//    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader  withReuseIdentifier:@"WHScrollAndPageView"];
    [self.view addSubview:_collectionView];
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return [User_information conversion].KROOM_Data.count;
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    CGSize size = CGSizeMake(WIDTH, 0);
    return size;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
//{
//    UIView *View = [[UIView alloc]init];
//    View.backgroundColor = [UIColor whiteColor];
//    View.userInteractionEnabled = YES;
//    if (indexPath.section == 0 ) {
//   
//        UIButton *butt = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
//        butt.backgroundColor = [UIColor whiteColor];
//        [butt addTarget:self action:@selector(ppp:) forControlEvents:(UIControlEventTouchUpInside)];
//        [View addSubview:butt];
//        
//        UILabel * name = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, WIDTH/2, 50)];
//        
//        name.text = @"| 人气周榜";
//        name.textColor=[UIColor orangeColor];
//        name.textAlignment=NSTextAlignmentLeft;
//        [View addSubview: name];
//        
//        
//        UILabel * more = [[UILabel alloc]initWithFrame:CGRectMake( WIDTH-100 , 0, 80, 50)];
////        more.text = @"全部 >>";
//        more.textColor=[UIColor orangeColor];
//        more.textAlignment=NSTextAlignmentRight;
//        [View addSubview:more];
//    }
//    else
//    {
//        
//        UIButton *butt = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
//        butt.backgroundColor = [UIColor whiteColor];
//        [butt addTarget:self action:@selector(ppp:) forControlEvents:(UIControlEventTouchUpInside)];
//        [View addSubview:butt];
//        
//        UILabel * name = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, WIDTH/2, 50)];
//        
//        name.text = @"|  人气总榜";
//        name.textColor=[UIColor orangeColor];
//        name.textAlignment=NSTextAlignmentLeft;
//        [View addSubview: name];
//        
//        UILabel * more = [[UILabel alloc]initWithFrame:CGRectMake( WIDTH-100 , 0, 80, 50)];
//        more.text = @"全部 >>";
//        more.textColor=[UIColor orangeColor];
//        more.textAlignment=NSTextAlignmentRight;
//        [View addSubview:more];
//    }
//    
//    if (kind == UICollectionElementKindSectionHeader){
//        UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"WHScrollAndPageView" forIndexPath:indexPath];
//        headerView.backgroundColor = [UIColor redColor];
//        [headerView addSubview:View];
//        return headerView;
//        
//    }else{
//        
//        return nil;
//        
//    }
//}

-(void)ppp:(UIButton*)button{
    
    NSLog(@"1-%ld",(long)button.tag);
    
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    [_collectionView registerClass:[K_ROOMCell class] forCellWithReuseIdentifier:@"K_ROOMCell"];
    
    K_ROOMCell*cell=(K_ROOMCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"K_ROOMCell" forIndexPath:indexPath];
    
    K_Mode * data =[[K_Mode alloc]init];
    
    data  = [User_information conversion].KROOM_Data[indexPath.row];
    
    cell.mylabel.text=[NSString stringWithFormat:@"%@ 人",data.peopleNumber];
    
    cell.room_num_label.text=[NSString stringWithFormat:@"%@",data.groupId];
    
    cell.my_name.text=[NSString stringWithFormat:@"%@",data.descriptionD];
    
    [cell.dt sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",data.pictureUrl]]];
    
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"%ld",indexPath.row);

}

//定义每一个cell大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize size;
    
    return CGSizeMake(WIDTH/2-2, HEIGHT/4);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    return 1;
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 1;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

